#pragma once
#include "Mutex.hpp"
namespace CondModule
{
    using namespace LockModule;

    class Cond
    {
    public:
        Cond()
        {
            int n = pthread_cond_init(&_cond,nullptr);
            if(n != 0)
            std::cerr << "cond init eroor" << std::endl;
        }
        void Notify()
        {
            int n = pthread_cond_signal(&_cond);
            (void)n;
        }
        void NotifyAll()
        {
            int n = pthread_cond_broadcast(&_cond);
            (void)n;
        }
        void Wait(Mutex& mutex)
        {
            int n = pthread_cond_wait(&_cond,mutex.LockPtr());
            (void)n;
        }
        ~Cond()
        {
            int n = pthread_cond_destroy(&_cond);
            if(n != 0)
            std::cerr << "cond destroy eroor" << std::endl;
        }
    private:        
        pthread_cond_t _cond;
    };
}